import logging

from base.connection import get_db_session
from conf import config

logger = logging.getLogger("wechat.helper.store")


def get_store_goods(store_id):
    """
    获取门店商品记录
    """
    class Goods(object):
        pass

    session = get_db_session(
        [
            {"db_table": "sdet_store_goods", "model": Goods},
        ]
    )

    filter = dict(
        sdef_goods_status=1,
        sdef_goods_is_visible=1,
        sdef_goods_is_delete=0,
        sdef_goods_store_id=store_id,
        sdef_goods_factory_uid=config.FACTORY_UID,
    )

    goods_array = (
        session.query(Goods)
        .filter_by(**filter)
        .order_by(Goods.sdef_goods_order_num.asc(), Goods.sdef_goods_price.asc())
        .all()
    )

    return goods_array


def get_store_goods_ids(store_id):
    """
    获取门店店内商品ID列表

    get_store_goods_ids(1)

    :param store_id:
    :return:
    """
    goods_array = get_store_goods(store_id)

    return [g.sdef_goods_id for g in goods_array]
